package com.hsq.ndmall.mall.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsq.ndmall.common.utils.PageUtils;
import com.hsq.ndmall.common.utils.Query;

import com.hsq.ndmall.mall.dao.TopicDao;
import com.hsq.ndmall.mall.entity.TopicEntity;
import com.hsq.ndmall.mall.service.TopicService;


@Service("topicService")
public class TopicServiceImpl extends ServiceImpl<TopicDao, TopicEntity> implements TopicService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TopicEntity> page = this.page(
                new Query<TopicEntity>().getPage(params),
                getQueryWrapper(params)
        );

        return new PageUtils(page);
    }

    private QueryWrapper getQueryWrapper(Map<String, Object> params) {
        QueryWrapper<TopicEntity> queryWrapper = new QueryWrapper<>();
        if(params.containsKey("related_id")){
            queryWrapper.lambda().ne(TopicEntity::getId,params.get("related_id"));
        }
        return queryWrapper;
    }
}
